import { createRouter, createWebHistory } from 'vue-router';
const { publicPath } = require('@/config');
const routes = [
	// 首页
	{
		path: '/index',
		name: 'index',
		component: () => import('@/views/index.vue'),
		meta: {
			title: '首页',
			needLogin: false,
		},
	},// 分类
	{
		path: '/category',
		name: 'category',
		component: () => import('@/views/category.vue'),
		meta: {
			title: '分类',
			needLogin: false,
		},
	},// 发现
	{
		path: '/found',
		name: 'found',
		component: () => import('@/views/found.vue'),
		meta: {
			title: '发布',
			needLogin: true,
		},
	},// 购物车
	{
		path: '/shopcar',
		name: 'shopcar',
		component: () => import('@/views/shopcar.vue'),
		meta: {
			title: '购物车',
			needLogin: true,
		},
	},
	// 我的
	{
		path: '/my',
		name: 'my',
		component: () => import('@/views/my.vue'),
		meta: {
			title: '我的',
			needLogin: false,
		},
	},
	// 地址列表
	{
		path: '/addressList',
		name: 'addressList',
		component: () => import('@/views/addressList.vue'),
		meta: {
			title: '地址列表',
			needLogin: true,
		},
	},
	// 地址编辑
	{
		path: '/addressEdit',
		name: 'addressEdit',
		component: () => import('@/views/addressEdit.vue'),
		meta: {
			title: '地址编辑',
			needLogin: true,
		},
	},
		// 登录
		{
			path: '/login',
			name: 'login',
			component: () => import('@/views/login.vue'),
			meta: {
				title: '登录',
				needLogin: false,
			},
		},// 商品详情
		{
			path: '/shopDetail',
			name: 'shopDetail',
			component: () => import('@/views/shopdetail.vue'),
			meta: {
				title: '商品详情',
				needLogin: false,
			},
		},
		// 我的订单
		{
			path: '/myOrder',
			name: 'myOrder',
			component: () => import('@/views/myorder.vue'),
			meta: {
				title: '我的订单',
				needLogin: true,
			},
		},
		// 设置
		{
			path: '/myPublish',
			name: 'myPublish',
			component: () => import('@/views/mypublish.vue'),
			meta: {
				title: '我的发布',
				needLogin: true,
			},
		},
		// 设置
		{
			path: '/createOrder',
			name: 'createOrder',
			component: () => import('@/views/createorder.vue'),
			meta: {
				title: '创建订单',
				needLogin: true,
			},
		},
		// 设置
		{
			path: '/account',
			name: 'account',
			component: () => import('@/views/account.vue'),
			meta: {
				title: '账号设置',
				needLogin: true,
			},
		},
	//重定向
	{
		path: '/:catchAll(.*)',
		redirect: '/index'
	},
];

const router = createRouter({
	history: createWebHistory(process.env.VUE_APP_ENV==='test'? publicPath:''),
	routes,
	//回滚到left top 0 0位置
	scrollBehavior(to, from, savedPosition) {
		return {
			left: 0,
			top: 0,
		};
	},
});

export default router;
